<?php
function create_menu_structurefiles($xml_content, $menu_content, $settings_content, $settings_css){
	global $settings;
	file_put_contents($settings['xml_structurefile'],$xml_content);
	file_put_contents($settings['menu_structurefile'],$menu_content);
	file_put_contents($settings['settingsfile'], $settings_content);
	file_put_contents($settings['cssfile'], $settings_css);
	$oR = new xajaxResponse();
	$oR->addRedirect("",1);
	//$oR->addAssign('menu_test_div','innerHTML',$menu_content.$settings_content);
	//$oR->addScript("listMenu.activateMenu('listMenuRoot', arrow);");
//	$oR->addScript("alert('Structurefiles created!')");
	return $oR;
}
function create_menu_targetfiles($xml_content, $menu_content, $settings_content, $settings_css){
	global $mb;
	create_menu_structurefiles($xml_content, $menu_content, $settings_content, $settings_css);
	$error = "";
	if($mb->s['target_save']){
		if(!copy($mb->s['xml_structurefile'], $mb->s['target_xml_structurefile'])) $error.='failed to copy the xml_structurefile\n';
		if(!copy($mb->s['menu_structurefile'], $mb->s['target_menu_structurefile'])) $error.='failed to copy the menu_structurefile\n';
		if(!copy($mb->s['settingsfile'], $mb->s['target_settingsfile'])) $error.='failed to copy the settingsfile\n';
		if(!copy($mb->s['cssfile'], $mb->s['target_cssfile'])) $error.='failed to copy the cssfile\n';
	}else{
		$error.='target_save setting is set to false\n';
	}

	$oR = new xajaxResponse();
	$message = strlen($error)?$error:'Menu saved';
	$oR->addScript('alert("'.$message.'");'.($mb->s['target_save']?'window.opener.location.reload();':'').'window.close();');
	return $oR;
}
require("configuration.php");
$xajax->processRequests();
?>
